/*
 * Powered By [leyvi]
 * Since 2014 - 2015
 */


var activity = {};
var common = require('../../utils/commonUtils');
//db转换成model
activity.dbConvertModel = function(db){
	var activity = {}; 
	if(common.isNotBlank(db.id)) activity.id = db.id;	
	if(typeof db.title != "undefined") activity.title = db.title;
	if(typeof db.img_url != "undefined") activity.imgUrl = db.img_url;
	if(typeof db.content != "undefined") activity.content = db.content;
	if(common.isNotBlank(db.current_num)) activity.currentNum = db.current_num;	
	if(common.isNotBlank(db.total_num)) activity.totalNum = db.total_num;	
	if(common.isNotBlank(db.start_time)){
		activity.startTime = db.start_time;
		activity.startTimeStr = db.start_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.end_time)){
		activity.endTime = db.end_time;
		activity.endTimeStr = db.end_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.create_time)){
		activity.createTime = db.create_time;
		activity.createTimeStr = db.create_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.update_time)){
		activity.updateTime = db.update_time;
		activity.updateTimeStr = db.update_time.format('yyyy-MM-dd hh:mm');
	} 		
	if(common.isNotBlank(db.bak1)) activity.bak1 = db.bak1;	
	if(common.isNotBlank(db.bak2)) activity.bak2 = db.bak2;	
	if(common.isNotBlank(db.bak3)) activity.bak3 = db.bak3;	
	if(typeof db.bak4 != "undefined") activity.bak4 = db.bak4;
	if(typeof db.bak5 != "undefined") activity.bak5 = db.bak5;
	return activity;
};

//model转换成db
activity.modelConvertDb = function(obj){
	var db = {}; 
	if(common.isNotBlank(obj.id)) db.id = obj.id;
	if(typeof obj.title != "undefined") db.title = obj.title;
	if(typeof obj.imgUrl != "undefined") db.img_url = obj.imgUrl;
	if(typeof obj.content != "undefined") db.content = obj.content;
	if(common.isNotBlank(obj.currentNum)) db.current_num = obj.currentNum;
	if(common.isNotBlank(obj.totalNum)) db.total_num = obj.totalNum;
	if(common.isNotBlank(obj.startTime)) db.start_time = obj.startTime;
	if(common.isNotBlank(obj.endTime)) db.end_time = obj.endTime;
	if(common.isNotBlank(obj.createTime)) db.create_time = obj.createTime;
	if(common.isNotBlank(obj.updateTime)) db.update_time = obj.updateTime;
	if(common.isNotBlank(obj.bak1)) db.bak1 = obj.bak1;
	if(common.isNotBlank(obj.bak2)) db.bak2 = obj.bak2;
	if(common.isNotBlank(obj.bak3)) db.bak3 = obj.bak3;
	if(typeof obj.bak4 != "undefined") db.bak4 = obj.bak4;
	if(typeof obj.bak5 != "undefined") db.bak5 = obj.bak5;
	return db;
};

activity.initPostReq = function(req){
	var activity = {};
	if(req.body.id != undefined){
		(typeof req.body.id != 'string') ? (activity.id = req.body.id) : (activity.id = req.body.id.trim());
	}
	if(req.body.title != undefined){
		(typeof req.body.title != 'string') ? (activity.title = req.body.title) : (activity.title = req.body.title.trim());
	}
	if(req.body.imgUrl != undefined){
		(typeof req.body.imgUrl != 'string') ? (activity.imgUrl = req.body.imgUrl) : (activity.imgUrl = req.body.imgUrl.trim());
	}
	if(req.body.content != undefined){
		(typeof req.body.content != 'string') ? (activity.content = req.body.content) : (activity.content = req.body.content.trim());
	}
	if(req.body.currentNum != undefined){
		(typeof req.body.currentNum != 'string') ? (activity.currentNum = req.body.currentNum) : (activity.currentNum = req.body.currentNum.trim());
	}
	if(req.body.totalNum != undefined){
		(typeof req.body.totalNum != 'string') ? (activity.totalNum = req.body.totalNum) : (activity.totalNum = req.body.totalNum.trim());
	}
	if(req.body.startTime != undefined){
		(typeof req.body.startTime != 'string') ? (activity.startTime = req.body.startTime) : (activity.startTime = req.body.startTime.trim());
	}
	if(req.body.endTime != undefined){
		(typeof req.body.endTime != 'string') ? (activity.endTime = req.body.endTime) : (activity.endTime = req.body.endTime.trim());
	}
	if(req.body.createTime != undefined){
		(typeof req.body.createTime != 'string') ? (activity.createTime = req.body.createTime) : (activity.createTime = req.body.createTime.trim());
	}
	if(req.body.updateTime != undefined){
		(typeof req.body.updateTime != 'string') ? (activity.updateTime = req.body.updateTime) : (activity.updateTime = req.body.updateTime.trim());
	}
	if(req.body.bak1 != undefined){
		(typeof req.body.bak1 != 'string') ? (activity.bak1 = req.body.bak1) : (activity.bak1 = req.body.bak1.trim());
	}
	if(req.body.bak2 != undefined){
		(typeof req.body.bak2 != 'string') ? (activity.bak2 = req.body.bak2) : (activity.bak2 = req.body.bak2.trim());
	}
	if(req.body.bak3 != undefined){
		(typeof req.body.bak3 != 'string') ? (activity.bak3 = req.body.bak3) : (activity.bak3 = req.body.bak3.trim());
	}
	if(req.body.bak4 != undefined){
		(typeof req.body.bak4 != 'string') ? (activity.bak4 = req.body.bak4) : (activity.bak4 = req.body.bak4.trim());
	}
	if(req.body.bak5 != undefined){
		(typeof req.body.bak5 != 'string') ? (activity.bak5 = req.body.bak5) : (activity.bak5 = req.body.bak5.trim());
	}
	return activity;
};

activity.initGetReq = function(req){
	var activity = {};
	if(req.query.id != undefined){	
		(typeof req.query.id != 'string') ? (activity.id = req.query.id) : (activity.id = req.query.id.trim());
	}
	if(req.query.title != undefined){	
		(typeof req.query.title != 'string') ? (activity.title = req.query.title) : (activity.title = req.query.title.trim());
	}
	if(req.query.imgUrl != undefined){	
		(typeof req.query.imgUrl != 'string') ? (activity.imgUrl = req.query.imgUrl) : (activity.imgUrl = req.query.imgUrl.trim());
	}
	if(req.query.content != undefined){	
		(typeof req.query.content != 'string') ? (activity.content = req.query.content) : (activity.content = req.query.content.trim());
	}
	if(req.query.currentNum != undefined){	
		(typeof req.query.currentNum != 'string') ? (activity.currentNum = req.query.currentNum) : (activity.currentNum = req.query.currentNum.trim());
	}
	if(req.query.totalNum != undefined){	
		(typeof req.query.totalNum != 'string') ? (activity.totalNum = req.query.totalNum) : (activity.totalNum = req.query.totalNum.trim());
	}
	if(req.query.startTime != undefined){	
		(typeof req.query.startTime != 'string') ? (activity.startTime = req.query.startTime) : (activity.startTime = req.query.startTime.trim());
	}
	if(req.query.endTime != undefined){	
		(typeof req.query.endTime != 'string') ? (activity.endTime = req.query.endTime) : (activity.endTime = req.query.endTime.trim());
	}
	if(req.query.createTime != undefined){	
		(typeof req.query.createTime != 'string') ? (activity.createTime = req.query.createTime) : (activity.createTime = req.query.createTime.trim());
	}
	if(req.query.updateTime != undefined){	
		(typeof req.query.updateTime != 'string') ? (activity.updateTime = req.query.updateTime) : (activity.updateTime = req.query.updateTime.trim());
	}
	if(req.query.bak1 != undefined){	
		(typeof req.query.bak1 != 'string') ? (activity.bak1 = req.query.bak1) : (activity.bak1 = req.query.bak1.trim());
	}
	if(req.query.bak2 != undefined){	
		(typeof req.query.bak2 != 'string') ? (activity.bak2 = req.query.bak2) : (activity.bak2 = req.query.bak2.trim());
	}
	if(req.query.bak3 != undefined){	
		(typeof req.query.bak3 != 'string') ? (activity.bak3 = req.query.bak3) : (activity.bak3 = req.query.bak3.trim());
	}
	if(req.query.bak4 != undefined){	
		(typeof req.query.bak4 != 'string') ? (activity.bak4 = req.query.bak4) : (activity.bak4 = req.query.bak4.trim());
	}
	if(req.query.bak5 != undefined){	
		(typeof req.query.bak5 != 'string') ? (activity.bak5 = req.query.bak5) : (activity.bak5 = req.query.bak5.trim());
	}
	return activity;
};


module.exports = activity;
